//package com.caiyi.financial.nirvana.sms.scheduled;
//
//import com.alibaba.fastjson.JSON;
//import com.caiyi.financial.nirvana.sms.enums.MessageActionEnum;
//import com.caiyi.financial.nirvana.sms.enums.SmsMsgStatusEnum;
//import com.caiyi.financial.nirvana.sms.jedis.JedisKey;
//import com.caiyi.financial.nirvana.sms.jedis.JedisService;
//import com.caiyi.financial.nirvana.sms.queue.SendQueueEntity;
//import com.caiyi.financial.nirvana.sms.service.SmsMsgService;
//import com.caiyi.financial.nirvana.sms.util.Constant;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.*;
//
//@Component
//public class PushMsgTask {
//
//    private static final Logger logger = LoggerFactory.getLogger(PushMsgTask.class);
//    @Autowired
//    private SmsMsgService smsMsgService;
//
//    /**
//     * 定时任务一个小时执行一次
//     * 更改一天之前的短信发送中、提交成功为发送失败并推送给用用户。
//     */
//    @Scheduled(fixedRate = Constant.TEN_MINUTES_OF_SECOND * 6 * 1000, initialDelay = Constant.TEN_MINUTES_OF_SECOND * 6 * 1000)
//    public void pushMsg() {
//        try {
//            List<SendQueueEntity> maps = smsMsgService.handleUnknownStatus();
//            Set<String> delKeys = new HashSet<>();
//            if (maps != null && !maps.isEmpty()) {
//                for (SendQueueEntity entity : maps) {
//                    if (StringUtils.isNotBlank(entity.getResult())) {
//                        delKeys.add(entity.getResult());
//                    }
//                    entity.setStatus(SmsMsgStatusEnum.SEND_FAIL.index);
//                    entity.setResult("CY:超时失败");
//                    entity.setAction(MessageActionEnum.CALLBACK.index);
//                    JedisService.lpush(JedisKey.SMS_QUEUE_MSG_DB, JSON.toJSONString(entity));
//                }
//            }
//            long count = 0;
//            //删除remote_id和message_id的对应关系
//            if (!delKeys.isEmpty()) {
//                count = JedisService.hdel(JedisKey.SMS_REMOTE_ID_MESSAGE_ID, delKeys.toArray(new String[delKeys.size()]));
//            }
//            logger.info("PushMsgTask更改数据状态条数 : {}, redis del : {}", maps.size(), count);
//        } catch (Exception e) {
//            logger.error("PushMsgTask error", e);
//        }
//    }
//
//}
